#-*- coding:utf-8 -*-
import sys
from PySide2.QtWidgets import *
from PySide2.QtGui import *
from PySide2.QtCore import *


class StatusComb(QWidget):
    status_Signal=Signal(tuple)
    def __init__(self,pos,index):
        super(StatusComb,self).__init__()
        # self.setStyleSheet('background-color:rgb(100,100,100)')
        self.styles=['QComboBox{color:#FFA500}','QComboBox{color:#90EE90}','QComboBox{color:#FF0000}','QComboBox{color:#696969}']

        self.pos=pos

        self.comb=QComboBox()
        self.status=['制作中','通过','返修','暂停']
        self.comb.addItems(self.status)

        self.comb.setFont(QFont('',12,75))
        self.comb.setStyleSheet('QComboBox{color:#FFA500;background-color:rgb(100,100,100)}')
        # self.comb.setStyleSheet('background-color:rgb(100,100,100)')
        self.comb.setCurrentIndex(index)#预设内容
        self.__preSetColor(index)#预设颜色
        self.comb.currentIndexChanged.connect(self.__changeComb)


        self.comb_layout=QHBoxLayout()
        self.comb_layout.addWidget(self.comb)
        self.comb_layout.setAlignment(Qt.AlignCenter)
        self.comb_layout.setContentsMargins(5,2,5,2)
        self.setLayout(self.comb_layout)

        # self.setStatus(2)

    def __preSetColor(self,i):
        '''
        初始化设置颜色用的，不要实例化后setStatus，因为会监听到，导致重写一遍数据。
        :param i:
        :return:
        '''

        self.comb.setStyleSheet(self.styles[i])



    def __changeComb(self,i):
        # styles=['QComboBox{color:#FFA500;background-color:rgb(100,100,100)}','QComboBox{color:#90EE90;background-color:rgb(100,100,100)}','QComboBox{color:#FF0000;background-color:rgb(100,100,100)}','QComboBox{color:#696969;background-color:rgb(100,100,100)}']

        self.comb.setStyleSheet(self.styles[i])

        temp_tuple=(self.pos,i)
        print('当前comb的索引为{}'.format(i))
        self.status_Signal.emit(temp_tuple)

    def setStatus(self,num):
        '''
        更改状态类型,不要用这个来初始化状态，因为它会被currentIndexChanged监听到，初始化使用自带的setCurrentIndex来
        :param num:int类型
        :return:
        '''
        print('正常情况，设置状态后不会再有当前comb索引为')
        self.comb.setCurrentIndex(num)


if __name__ == '__main__':
    app=QApplication(sys.argv)
    sc=StatusComb((0,0),1)
    sc.show()
    sys.exit(app.exec_())